package com.qf.search.mq;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.search.service.SearchService;
import com.qianfeng.smsplatform.common.constants.RabbitMqConsants;
import com.qianfeng.smsplatform.common.model.Standard_Submit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 徐老板
 * @date 2020/3/3   16:01
 */
@Component
public class ReceiveFromMq {
    //这里收的消息是从接口模块收到的 所以要去接口模块定义发送消息的代码以及队列

    private static final Logger LOGGER = LoggerFactory.getLogger(ReceiveFromMq.class);
    @Resource
    private SearchService searchService;
    @Resource
    private ObjectMapper objectMapper;

    //这个队列名字是在rabbitmq配置中提前定义好的
    @RabbitListener(queues = RabbitMqConsants.TOPIC_SMS_SEND_LOG,containerFactory = "taskContainerFactory")
    public void receiveSubmit(Standard_Submit submit){
        try {
            LOGGER.error("search模块收到了发送短信的消息{}",submit);
            searchService.addIndex(objectMapper.writeValueAsString(submit));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
